<?php
// -----------------------------------------------------------------------------
// 引入
// -----------------------------------------------------------------------------

include "../config/config.php";
include "../auth.php";
include "../DBManager.php";
include "../resources/Snowflake/HighConcurrencySnowflake.php";

// -----------------------------------------------------------------------------
// 访问设置
// -----------------------------------------------------------------------------

if (!isset($_GET["linkId"]) || !isset($_GET["targetCategoryId"])) {
    exit("需要传入有效的参数！");
}

$linkId = $_GET["linkId"];
$targetCategoryId = $_GET["targetCategoryId"];

// -----------------------------------------------------------------------------
// 数据库相关设置
// -----------------------------------------------------------------------------

$dbPath = "../" . $dbPath; // 不加这行语句的话会报错，提示找不到对应路径
$db = new DBManager("sqlite:" . $dbPath);

// -----------------------------------------------------------------------------
// 时区设置
// -----------------------------------------------------------------------------

date_default_timezone_set($region);

$now = time();
$timeLastMove = $now;

// -----------------------------------------------------------------------------

/* 使用雪花算法生成排序号 */
$snowflake = new HighConcurrencySnowflake();
$sortNumber = $snowflake->nextId();

// -----------------------------------------------------------------------------

$db->changeLinkAttrCategoryId($linkId, $targetCategoryId, $timeLastMove);
$db->changeLinkAttrSortNumber($linkId, $sortNumber);
